/*
 * @Author: your name
 * @Date: 2021-11-12 21:39:15
 * @LastEditTime: 2021-12-02 14:08:51
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\serve\app\controller\article.js
 */
/*
 * @Author: your name
 * @Date: 2021-11-09 16:30:21
 * @LastEditTime: 2021-11-10 08:33:33
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\egg-example\app\controller\home.js
 */
const Mock = require("mockjs");
const { list } = Mock.mock({
    "list|20": [{
        author: "@ctitle",
        content: "@cword(10,40)",
        title: "@ctitle(10,20)",
        likes: 0,
        comment_num: 0,
        looks: 0,
        release_time: "@datetime",
        alter_time: "@datetime",
        "state|1": [false, true],
        tag: ["哈哈"],
        "classify|1": ["无", "111"],
        "focus|1": [false, true],
    }, ],
});
const Controller = require("../core/base_controller");
class ArticleController extends Controller {
    async insertList() {
            const { ctx, app } = this;
            list.forEach((item) => {
                app.mysql.insert("allarticle", {...item });
            });
            ctx.body = "添加成功";
        }
        //获取
    async getArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //获取最新文章
    async getNewArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getNewArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //获取详情
    async getDetail() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getDetail();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //编辑内容
    async editDetail() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.editDetail();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //新增文章
    async addArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.addArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //获取文章个数
    async getArticleTotal() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getArticleTotal();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //删除
    async delArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.delArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //改变首焦状态

    async changeArticleFocus() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.changeArticleFocus();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量删除
    async batchDelArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.batchDelArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量发布
    async batchPubArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.batchPubArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量草稿
    async batchDftArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.batchDftArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量撤销
    async batchRemoveArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.batchRemoveArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量推荐
    async batchFocusArticle() {
        const { ctx } = this;
        try {
            const res = await ctx.service.article.batchFocusArticle();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }

    // **********用户端****************//
    //批量推荐
    async searchArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.searchArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //推荐阅读
    async recommendArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.recommendArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //获取上线文章
    async getStateArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getStateArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //首焦推荐轮播图数据
    async getFocusArticle() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.getFocusArticle();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //阅读量++
    async addArticleReading() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.addArticleReading();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //点赞
    async addArticleLikes() {
            const { ctx } = this;
            try {
                const res = await ctx.service.article.addArticleLikes();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //点赞
    async isArticleLikes() {
        const { ctx } = this;
        try {
            const res = await ctx.service.article.isArticleLikes();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }
}

module.exports = ArticleController;